﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using DevExpress.XtraGrid.Columns;
using System.Reflection;
using Ebada.Client;
using DevExpress.XtraGrid.Views.Base;
using Ebada.Client.Platform;
using Ebada.UI.Base;
namespace Ebada.Modules.Vehicle
{

    public partial class UCVehicleKilometer : DevExpress.XtraEditors.XtraUserControl {
        private GridViewOperation<VehicleKilometer> gridViewOperation;

        public event SendDataEventHandler<VehicleKilometer> FocusedRowChanged;
        public static bool FirstLoad = false;
        public UCVehicleKilometer() 
        {
            InitializeComponent();
           
            gridViewOperation = new GridViewOperation<VehicleKilometer>(gridControl1, gridView1, barManager1,new frmVehicleKilometerEdit());
            gridViewOperation.CreatingObjectEvent +=gridViewOperation_CreatingObjectEvent;
            gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gridViewOperation_FocusedRowChanged);
            gridViewOperation.BeforeAdd += new ObjectOperationEventHandler<VehicleKilometer>(gridViewOperation_BeforeAdd);
            initColumns();
            InitData();
        }

        void gridViewOperation_BeforeAdd(object render, ObjectOperationEventArgs<VehicleKilometer> e)
        {
            //int Count=MainHelper.PlatformSqlMap.GetRowCount<VehicleKilometer>("");
            //e.Value.VehicleCode =( Count + 1).ToString();
            e.Value.StartDate = DateTime.Now;
            e.Value.EndDate = DateTime.Now;
        }

        void gridViewOperation_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) 
        {
            if (FocusedRowChanged != null)
                FocusedRowChanged(gridView1, gridView1.GetFocusedRow() as VehicleKilometer);
        }
        


       
        /// <summary>
        /// 设置隐藏列
        /// </summary>
        /// 
       public  void initColumns() 
        {

            gridView1.Columns[2].Caption = "本期开始日期";
            gridView1.Columns[3].Caption = "期初公里数";
            gridView1.Columns[4].Caption = "本期截止日期";
            gridView1.Columns[5].Caption = "期末公里数";
            gridView1.Columns[6].Caption = "本期实际公里数";
            gridView1.Columns[7].Caption = "备注";
        }
      
    
        /// <summary>
        /// 封装了数据操作的对象
        /// </summary>
        [Browsable(false)]
       public GridViewOperation<VehicleKilometer> GridViewOperation
       {
            get { return gridViewOperation; }
            set { gridViewOperation = value; }
        }
        /// <summary>
        /// 新建对象设置Key值
        /// </summary>
        /// <param name="newobj"></param>
        void gridViewOperation_CreatingObjectEvent(VehicleKilometer newobj)
        {
            //newobj.VehicleKilometerID = Guid.NewGuid().ToString();
           
        }

        public void InitData()
        {
            gridViewOperation.RefreshData("");
        }
      
       

    }
}
